package com.guanzhi.aop.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * Spring6
 * <p> Package: com.guanzhi.aop.aspect </p>
 * <p> File: AnnotationNoticeAspect.java </p>
 * <p> Description:  (AOP 实现 切面)</p>
 * <p> Date: 2024/8/18 19:56</p>
 *
 * @author LiKai
 * @version 1.0 （代码版本）
 * @email <a href="mailto:Likai55634@aliyun.com">LiKai</a>（邮箱）
 * @date 2024/8/18 19:56
 * @since jdk1.8（jdk版本）
 */
@Aspect
@Component
public class AnnotationNoticeAspect {

    /**
     * 重用切点
     */
    @Pointcut(value = "execution(* com.guanzhi.aop.service.impl.CalculatorServiceImpl.add(..))")
    private void pointCut() {}

    /**
     * 前置通知
     */
    @Before(value = "pointCut()")
    public void beforeMethod(JoinPoint joinPoint) {
        System.out.println("前置通知");
    }

    /**
     * 后置通知
     */
    @After(value = "pointCut()")
    public void afterMethod(JoinPoint joinPoint) {
        System.out.println("后置通知");
    }

    /**
     * 环绕通知
     */
    @Around(value = "pointCut()")
    public Object aroundMethod(ProceedingJoinPoint point) throws Throwable {
        System.out.println("坏绕通知");
        return point.proceed();
    }

    /**
     * 异常通知
     */
    @AfterThrowing(value = "pointCut()", throwing = "exception")
    public void afterThrowingMethod(JoinPoint joinPoint, Exception exception) {
        System.out.println("异常通知");
    }

    /**
     * 最终通知
     */
    @AfterReturning(value = "pointCut()",returning = "result")
    public void afterReturningMethod(JoinPoint joinPoint, Object result) {
        System.out.println("最终通知");
    }
}
